package com.richman.ps38;


import jdk.incubator.http.HttpClient;
import jdk.incubator.http.HttpClient.Version;
import jdk.incubator.http.HttpRequest;
import jdk.incubator.http.HttpResponse;



import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import java.io.IOException;
import java.net.*;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;

import org.json.*;

import com.richman.controller.DaShui;
import com.richman.ps38.entity.Event;



/**
 * Created by bgt on 2017/10/1.
 * Java9http示例
 * <p>
 * VM 参数中添加模块支持
 * --add-modules jdk.incubator.httpclient
 */




public class PS38Http {
	

    HttpClient client = null;

    CookieManager cookieManager = new CookieManager();
    
    
    boolean hasLang = false;
    
    long canGetMainPageTime = -1;
    
    
    //-1 最初状态  ,  0 prepareLogin成功, 1 get main page success, 2 登录成功, -2 登录失败,  3抓取成功, -3抓取失败
    int statusCode = -1;
    
    
    String ADDRESS = "https://www.ps3838.com/";
    String ACCOUNT = "";
    String PWD = "";
    
     {
    	 
    	 init();
     
     }
     
     public long getCanGetMainPageTime() {
    	 return canGetMainPageTime;
     }
     
     public int getStatusCode() {
    	 
    	 
    	 
    	 return statusCode;
     }
     
     
     private void updateStatusCode(int i) {
    	 
    	 if(statusCode == -1 && i == 0) {
    		 canGetMainPageTime = System.currentTimeMillis() + 10*1000;
    	 }else if(i == 0) {
    		 canGetMainPageTime = System.currentTimeMillis() + 20*1000;
    	 }
    	 
    	 System.out.println("update ps38_statusCode from " +   Integer.toString(statusCode) + " to " + Integer.toString(i));
    	 
    	 statusCode = i;
     }
     
     
     public void prepareLogin() {
    	 String res = HttpGet();
    	 
    	 if(res.toLowerCase().contains("name=\"robots\"")) {
    		 updateStatusCode(0);
    	 }else if(res.contains("htmlMainclass")) {
    		 updateStatusCode(1);
    	 }
    	 
     }
     
     public void getMainPage() {
    	 
    	 String res = HttpGet();
    	 
    	 if(res.contains("htmlMainclass")) {
    		 updateStatusCode(1);
    	 }else if(res.toLowerCase().contains("name=\"robots\"")) {
    		 updateStatusCode(0);
    	 }
    	 
     }
     
     
     public  void setLoginParams(String address, String account, String pwd){
			
			ADDRESS = address;
			ACCOUNT = account;
			PWD = pwd;
	}
     



    public  void init(){
        try {
//            Authenticator authenticator=new Authenticator() {
//            };

            X509TrustManager x509m = new X509TrustManager() {  
            	  
                @Override  
                public X509Certificate[] getAcceptedIssuers() {  
                    return null;  
                }  
          
                @Override  
                public void checkServerTrusted(X509Certificate[] chain,  
                        String authType) throws CertificateException {  
                }  
          
                @Override  
                public void checkClientTrusted(X509Certificate[] chain,  
                        String authType) throws CertificateException {  
                }  
            };  
            // 获取一个SSLContext实例  
            SSLContext s = SSLContext.getInstance("SSL");  
            // 初始化SSLContext实例  
            s.init(null, new TrustManager[] { x509m },  
                    new java.security.SecureRandom());  
            
            
            
            
            
            
            
            
        client= HttpClient.newBuilder()
                //.authenticator(authenticator)//配置authenticator
                .sslContext(s)//配置 sslContext
                .sslParameters(new SSLParameters())//配置 sslParameters
//                .sslParameters(new SSLParameters(new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA" },
//                        new String[] { "TLSv1.2" }))//配置 sslParameters
                .proxy(ProxySelector.getDefault())//配置 proxy
                .executor(Executors.newCachedThreadPool())//配置 executor
                .followRedirects(HttpClient.Redirect.ALWAYS)//配置 followRedirects
                .cookieHandler(cookieManager)//配置 cookieManager
                .version(HttpClient.Version.HTTP_2)//配置 version
                .build();

    } catch (Exception e) {
        e.printStackTrace();
    }
    }
    /**
     * 普通get方式
     *
     *
     * 结果:{
     "msg" : "未查询到用户,请认真检查账户或者是否登录",
     "success" : false
     }
     响应码:200

     */
    public  String HttpGet() {
    	
    	
    	
    	try {
    		
    		
            HttpRequest request = HttpRequest
                    //.newBuilder(URI.create("http://hga020.com/"))
                    .newBuilder(URI.create(ADDRESS + "zh-cn/"))
                    //.header("Host", "www.ps3838.com")//携带的参数
                    .header("Accept-Encoding", "")
                    .header("Connection", "keep-alive")
                    .header("Upgrade-Insecure-Requests", "1")
                    .header("Pragma", "no-cache")
                    .header("Cache-Control", "no-cache")
                    .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0")
                    .header("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
                    .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
                    .version(Version.HTTP_2)
                    .timeout(Duration.ofSeconds(30))//2秒过期
                    .GET()
                    .build();
            
            
            
            
            
            
            
//            CookieStore cookieJar = cookieManager.getCookieStore();
//            List<HttpCookie> cookies = cookieJar.getCookies();
            
            
            
//            System.out.println("current cookies:");
//            
//            for (HttpCookie cookie : cookies) {
    //
//              System.out.println(cookie);
//            }
//          
            

            
            return getReponse(request);
    		
    	}catch(Exception e) {
    		
    		e.printStackTrace();
    	}
    	

    	return "";

        

    }
    
    public String getAccount() {
    	return ACCOUNT;
    }

    
    
    public String updateMatches() {
    	
    	
    	
    	
    	try {
    		
    		
        	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式
        	
        	long currentTimeMillis = System.currentTimeMillis();
        	
        	String oduri = ADDRESS + "sports-service/sv/odds/events?mk=1&sp=29&ot=4&btg=1&o=1&lg=&ev=&d=" + df.format(currentTimeMillis) + "&l=3&v=0&me=0&more=false&c=CN&tm=0&g=&pa=0&_=" + currentTimeMillis + "&locale=zh_CN";
        	
        	
        	//														mk=1&sp=29&ot=4&btg=1&o=1&lg=&ev=&d=2018-11-22&l=3&v=0&more=false&c=CN&tm=0&g=QQ%3D%3D&pa=0&_=1542785438602&locale=zh_CN
        	
        	//https://www.ps3838.com/ sports-service/sv/odds/events?mk=1&sp=29&ot=1&btg=1&o=1&lg=&ev=&d=2018-11-22&l=3&v=1542785561407&more=false&c=CN&tm=0&g=QQ%3D%3D&pa=0&_=1542785438522&locale=zh_CN
        	
        	
        	//https://www.ps3838.com/sports-service/sv/odds/events?mk=2&sp=29&ot=4&btg=1&o=1&lg=&ev=&d=2018-11-21                          &l=3&v=1542709885876&more=false&c=CN&tm=0&g=QQ%3D%3D&pa=0&_=1542709206136&locale=zh_CN

        	
            HttpRequest request = HttpRequest
                    //.newBuilder(URI.create("http://hga020.com/"))
                    .newBuilder(URI.create(oduri))
                    //.header("Host", "www.ps3838.com")//携带的参数
                    
                    .header("Accept-Encoding", "")
                    .header("Referer", "https://www.ps3838.com/zh-cn/sports")
                    .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0")
                    .header("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
                    .header("Accept", "application/json, text/javascript, */*; q=0.01")
                    .header("X-Requested-With", "XMLHttpRequest")
                    .version(Version.HTTP_2)
                    .timeout(Duration.ofSeconds(20))//2秒过期
                    .GET()
                    .build();
            
            
            
            if(hasLang == false) {
                HttpCookie cookie1 = new HttpCookie("skin", "ps3838");
                cookie1.setDomain(".ps3838.com");
                cookie1.setPath("/");
                cookie1.setVersion(0);
                
                HttpCookie cookie2 = new HttpCookie("lang", "zh_CN");
                cookie2.setDomain(".ps3838.com");
                cookie2.setPath("/");
                cookie2.setVersion(0);
                
                cookieManager.getCookieStore().add(null, cookie1);
                cookieManager.getCookieStore().add(null, cookie2);
                
                hasLang = true;
            }
            

//            CookieStore cookieJar = cookieManager.getCookieStore();
//            List<HttpCookie> cookies = cookieJar.getCookies();
    //
//            
//            System.out.println("current cookies:");
    //
//            for (HttpCookie cookie : cookies) {
//            	
//            System.out.println("one cookie begin");
//              System.out.println("name:" + cookie.getName());
//              System.out.println("value:" + cookie.getValue());
//              System.out.println("domain" + cookie.getDomain());
//              System.out.println("path:" + cookie.getPath());
//              System.out.println("version:" + cookie.getVersion());
//              System.out.println("comment:" + cookie.getComment());
//              System.out.println("CommentURL:" + cookie.getCommentURL());
//              
//              System.out.println("whole:" + cookie);
//              
//              System.out.println("one cookie end");
    //
//            }
            
            String res = getReponse(request);

            if(res.toLowerCase().contains("name=\"robots\"")) {
            	updateStatusCode(0);
            	return res;
            }
            
            
            if(!res.contains("{")) {
            	return "";
            }
            
            parseMatches(res);
            
            return res;
    		
    	}catch(Exception e) {
    		e.printStackTrace();
    	}
    	
    	
    	return "";
    	
    }
    
    
    
    private void parseMatches(String matchStr) {
    	
    	String resout = "";
    	
    	try {
    		
    		PS38Manager.ps38Events.clear();
    		
    		
    		JSONObject sports = new JSONObject(matchStr);
    		
    		
    		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS");
    		
    		
    		
    		
    		//滚球盘
    		JSONArray rollGame = sports.getJSONArray("l");
    		JSONArray rollEvents = rollGame.getJSONArray(0);
    		rollEvents = rollEvents.getJSONArray(2);
    		
    		
    		
    		JSONArray oneLeague = null;
    		
    		for(int i = 0; i < rollEvents.length(); i++){
    			oneLeague = rollEvents.getJSONArray(i);
    			
    			String leagueName = oneLeague.getString(1);
    			
    			if(leagueName.contains("角球") || leagueName.contains("红黄牌") || leagueName.contains("晋级")) {
    				continue;
    			}
    			
    			JSONArray oneLeagueEvents = oneLeague.getJSONArray(2);
    			
    			
    			JSONArray oneEvent = null;
    			for(int j = 0; j < oneLeagueEvents.length(); j++) {
    				oneEvent = oneLeagueEvents.getJSONArray(j);
    				
    				long eventId = oneEvent.getLong(0);
    				String homeTeam = oneEvent.getString(1);
    				String awayTeam = oneEvent.getString(2);
    				long eventTime = oneEvent.getLong(4);
    				
    				
    				
    				
    				if(homeTeam.contains("角球") || homeTeam.contains("红黄牌") || homeTeam.contains("晋级")) {
        				continue;
        			}
    				
    				
    				
    				
    				JSONObject odds = oneEvent.getJSONObject(8);
    				
    				int homeTeamScore = 0;
    				int awayTeamScore = 0;
    				

    				try {
    					
        				homeTeamScore = oneEvent.getJSONArray(9).getInt(0);
        				awayTeamScore = oneEvent.getJSONArray(9).getInt(1);
    					
    					
    				}catch(Exception e) {
    					//e.printStackTrace();
    				}
    				
    				String duringTime = "";
    				
    				try {
    					duringTime = oneEvent.getString(16) + oneEvent.getString(15);
    				}catch(Exception e) {
    					
    				}
    				
    				
    				Event[] ps38event = {new Event(), new Event(), new Event(), new Event(), new Event()};
    				
    				
    				//Event ps38event = new Event();
    				
    				for(Event e: ps38event) {
        				e.eventId = eventId;
        				e.leagueName = leagueName;
        				e.homeTeam = homeTeam;
        				e.awayTeam = awayTeam;
        				e.eventTime = eventTime;
        				e.duringTime = duringTime;
        				e.homeTeamScore = homeTeamScore;
        				e.awayTeamScore = awayTeamScore;
    				}
    				

    				
    				boolean[] hasPankou = {false, false,false,false,false};
    				
//    				System.out.println(leagueName);
//    				
//    				System.out.println(eventId);
//    				System.out.println(homeTeam);
//    				System.out.println(awayTeam);
//    				System.out.println(df.format(eventTime));
//    				
//    				System.out.println(Integer.toString(homeTeamScore)+ ":" + Integer.toString(awayTeamScore));
//    				
//    				System.out.println(duringTime);
    				
    				
    				
    				
    				int len = odds.length();
    				
    				
    				if(len >=1 ) {
    					
    					if(!odds.has("0")) {
    						continue;
    					}
    					
    					
        				//全场
        				JSONArray whole = odds.getJSONArray("0");
        				
        				
        				
        				//全场让球盘盘口赔率
        				JSONArray wholeRQP = whole.getJSONArray(0);    	
        				
        				//System.out.println("wholeRQP:" + wholeRQP.toString());
        				
        				
        				
        				
        				for(int ii = 0; ii < wholeRQP.length(); ii++) {
        					
            				JSONArray wholeRQPDetail = wholeRQP.getJSONArray(ii);
            				
            				
            				//System.out.println("wholeRQPDetail:" + wholeRQPDetail.toString());
            				
//            				Double wholeRQPPankou = wholeRQPDetail.getDouble(2);
//            				Double wholeRQPPankouUp = wholeRQPDetail.getDouble(3);
//            				Double wholeRQPPankouDown = wholeRQPDetail.getDouble(4);
            				
            				Double wholeRQPPankou = wholeRQPDetail.getDouble(0);
            				String wholeRQPPankouUp = wholeRQPDetail.getString(3);
            				String wholeRQPPankouDown = wholeRQPDetail.getString(4);
            				
            				
            				String wholeRQPBetID = Long.toString(wholeRQPDetail.getLong(7));
            				
            				
            				
            				
            				
            				hasPankou[ii] = true;
            				ps38event[ii].wholerqppankou = Double.toString(wholeRQPPankou);
            				ps38event[ii].wholeRQPPankouUp = wholeRQPPankouUp;
            				ps38event[ii].wholeRQPPankouDown = wholeRQPPankouDown;
            				ps38event[ii].wholeRQPBetID = wholeRQPBetID;
            				
//            				System.out.println(wholeRQPPankou);
//            				System.out.println(wholeRQPPankouUp);
//            				System.out.println(wholeRQPPankouDown);
        					
        				}
        				
        				

        				
        				
        				
        				//全场大小球盘盘口赔率
        				JSONArray wholeDXP = whole.getJSONArray(1);
        				
        				for(int ii = 0; ii < wholeDXP.length(); ii++) {
            				JSONArray wholeDXPDetail = wholeDXP.getJSONArray(ii);
            				
            				
            				
            				
            				Double wholeDXPPankou = wholeDXPDetail.getDouble(1);
            				Double wholeDXPPankouUp = wholeDXPDetail.getDouble(2);
            				Double wholeDXPPankouDown = wholeDXPDetail.getDouble(3);
            				
            				String wholeDXPBetID = Long.toString(wholeDXPDetail.getLong(4));
            				
            				hasPankou[ii] = true;
            				ps38event[ii].wholeDXPPankou = Double.toString(wholeDXPPankou);
            				ps38event[ii].wholeDXPPankouUp = Double.toString(wholeDXPPankouUp);
            				ps38event[ii].wholeDXPPankouDown = Double.toString(wholeDXPPankouDown);
            				ps38event[ii].wholeDXPBetID = wholeDXPBetID;


        				}
        				

        				
    				}
    				



    				
    				for(int ii = 0; ii < hasPankou.length; ii++) {
    					if(hasPankou[ii] == true) {
        					PS38Manager.ps38Events.add(ps38event[ii]);
        				}
    				}
    				

    			}
    			
    		}
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		//单式盘
    		JSONArray danshiGame = sports.getJSONArray("n");
    		JSONArray danshiEvents = danshiGame.getJSONArray(0);
    		danshiEvents = danshiEvents.getJSONArray(2);
    		
    		
    		
    		//JSONArray oneLeague = null;
    		
    		for(int i = 0; i < danshiEvents.length(); i++){
    			oneLeague = danshiEvents.getJSONArray(i);
    			
    			String leagueName = oneLeague.getString(1);
    			
    			if(leagueName.contains("角球") || leagueName.contains("红黄牌") || leagueName.contains("晋级")) {
    				continue;
    			}
    			
    			JSONArray oneLeagueEvents = oneLeague.getJSONArray(2);
    			
    			
    			JSONArray oneEvent = null;
    			for(int j = 0; j < oneLeagueEvents.length(); j++) {
    				oneEvent = oneLeagueEvents.getJSONArray(j);
    				
    				
    				
    				long eventId = oneEvent.getLong(0);
    				String homeTeam = oneEvent.getString(1);
    				String awayTeam = oneEvent.getString(2);
    				long eventTime = oneEvent.getLong(4);
    				
    				JSONObject odds = oneEvent.getJSONObject(8);
    				
    				if(homeTeam.contains("角球") || homeTeam.contains("红黄牌") || homeTeam.contains("晋级")) {
        				continue;
        			}
    				
    				
    				int homeTeamScore = 0;
    				int awayTeamScore = 0;
    				

    				try {
    					
        				homeTeamScore = oneEvent.getJSONArray(9).getInt(0);
        				awayTeamScore = oneEvent.getJSONArray(9).getInt(1);
    					
    					
    				}catch(Exception e) {
    					//e.printStackTrace();
    				}
    				
    				String duringTime = "";
    				
    				try {
    					duringTime = oneEvent.getString(16) + oneEvent.getString(15);
    				}catch(Exception e) {
    					
    				}
    				
    				
    				
    				Event[] ps38event = {new Event(), new Event(), new Event(), new Event(), new Event()};
    				
    				
    				//Event ps38event = new Event();
    				
    				for(Event e: ps38event) {
        				e.eventId = eventId;
        				e.leagueName = leagueName;
        				e.homeTeam = homeTeam;
        				e.awayTeam = awayTeam;
        				e.eventTime = eventTime;
        				e.duringTime = duringTime;
        				e.homeTeamScore = homeTeamScore;
        				e.awayTeamScore = awayTeamScore;
    				}
    				

    				
    				boolean[] hasPankou = {false, false,false, false,false};
    				
//    				System.out.println(leagueName);
//    				
//    				System.out.println(eventId);
//    				System.out.println(homeTeam);
//    				System.out.println(awayTeam);
//    				System.out.println(df.format(eventTime));
//    				
//    				System.out.println(Integer.toString(homeTeamScore)+ ":" + Integer.toString(awayTeamScore));
//    				
//    				System.out.println(duringTime);
    				
    				
    				
    				
    				int len = odds.length();
    				
    				
    				if(len >=1 ) {
        				//全场
    					
    					//System.out.println("odds~~~~~~~~~~~" + odds.toString());
    					
    					resout = odds.toString();
    					
    					if(!odds.has("0")) {
    						continue;
    					}
    					
    					
        				JSONArray whole = odds.getJSONArray("0");
        				
        				
        				
        				//全场让球盘盘口赔率
        				JSONArray wholeRQP = whole.getJSONArray(0);    	
        				
        				//System.out.println("wholeRQP:" + wholeRQP.toString());
        				
        				
        				
        				
        				//if(wholeRQP.length() >0) {
        				for(int ii = 0; ii < wholeRQP.length(); ii++) {
        					
        				
        					
            				JSONArray wholeRQPDetail = wholeRQP.getJSONArray(ii);
            				

            				
            				Double wholeRQPPankou = wholeRQPDetail.getDouble(0);
            				String wholeRQPPankouUp = wholeRQPDetail.getString(3);
            				String wholeRQPPankouDown = wholeRQPDetail.getString(4);
            				
            				String wholeRQPBetID = Long.toString(wholeRQPDetail.getLong(7));
            				
            				hasPankou[ii] = true;
            				ps38event[ii].wholerqppankou = Double.toString(wholeRQPPankou);
            				ps38event[ii].wholeRQPPankouUp = wholeRQPPankouUp;
            				ps38event[ii].wholeRQPPankouDown = wholeRQPPankouDown;
            				ps38event[ii].wholeRQPBetID = wholeRQPBetID;

        					
        				}
        				
        				

        				
        				
        				
        				//全场大小球盘盘口赔率
        				JSONArray wholeDXP = whole.getJSONArray(1);

        				for(int ii = 0; ii< wholeDXP.length(); ii++) {
            				JSONArray wholeDXPDetail = wholeDXP.getJSONArray(ii);
            				
            				Double wholeDXPPankou = wholeDXPDetail.getDouble(1);
            				Double wholeDXPPankouUp = wholeDXPDetail.getDouble(2);
            				Double wholeDXPPankouDown = wholeDXPDetail.getDouble(3);
            				String wholeDXPBetID = Long.toString(wholeDXPDetail.getLong(4));
            				
            				
            				hasPankou[ii] = true;
            				ps38event[ii].wholeDXPPankou = Double.toString(wholeDXPPankou);
            				ps38event[ii].wholeDXPPankouUp = Double.toString(wholeDXPPankouUp);
            				ps38event[ii].wholeDXPPankouDown = Double.toString(wholeDXPPankouDown);
            				ps38event[ii].wholeDXPBetID = wholeDXPBetID;
        				}
    				}
    				

    				

    				for(int ii = 0; ii < hasPankou.length; ii++) {
    					if(hasPankou[ii] == true) {
        					PS38Manager.ps38Events.add(ps38event[ii]);
        				}
    				}
    				
    				
    				

    			}
    			
    		}
    		
    		
    		
    		
    		updateStatusCode(3);
    		
    		
    		DaShui.mainWnd.updatePS38EventsTable(PS38Manager.ps38Events);
    		
    		DaShui.mainWnd.updateTeamMatchPS38Teams(PS38Manager.ps38Events);
    		
    		DaShui.isnps38EventManager.updateps38events(PS38Manager.ps38Events);
    		
    		
    		
    	}catch(Exception e) {
    		e.printStackTrace();
    		
    		System.out.println("resout:" + resout);
    		
    		updateStatusCode(-3);
    	}
    	
    	
    }
    
    
    
    
    public boolean Login() {

   
        try {
        	
            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create(ADDRESS + "member-service/v1/login?locale=zh_CN"))
                    .header("Content-Type","application/x-www-form-urlencoded")
                    .header("Accept-Encoding", "")
                    .header("Connection", "keep-alive")
                    .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0")
                    .header("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
                    .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
                    .header("Referer", "https://www.ps3838.com/zh-cn/")
                    .header("Host", "www.ps3838.com")
                    .version(Version.HTTP_2)
                    .timeout(Duration.ofSeconds(10))//2秒过期
                    .POST(HttpRequest.BodyPublisher.fromString("loginId=004NN02000&password=aaaa2345"))
                    .build();


            
            
            
            
            
            if(getReponse(request).equals("1")) {
            	
            	updateStatusCode(2);
            	
            	return true;
            }else if(getReponse(request).equals("0")) {
            	updateStatusCode(-2);
            }
            
            
            
            return false;
        	
        }catch(Exception e) {
        	e.printStackTrace();
        }
        

        return false;

    }



    /**
     * 输出响应结果
     * @param request
     * @throws IOException
     * @throws InterruptedException
     */
    public  String getReponse(HttpRequest request) {
    	
    	
    	
    	
    	
    	try {
    		
    		
    		
    		
    		
            HttpResponse<String> response = null;
            
            if (client==null) {
                init();
            }
            response = client.send(request, HttpResponse.BodyHandler.asString(Charset.forName("UTF-8")));
            
            
            if(response == null) {
            	return "";
            }
            
            //String result = response.body();
            
            String result = "";
    		
    		result = new String(response.body().getBytes(Charset.forName("UTF-8")));

    		//System.out.println(response.headers().toString());

            int code = response.statusCode();
            if (code == 200) {
                //System.out.println("结果:" + result);
                
                System.out.println("response version:" + response.version());
                
            }
            
            
            System.out.println("响应码:" + code);
            
            return result;
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    		
    	}catch(Exception e) {
    		e.printStackTrace();
    	}
    	
    	return "";
    	

    }



}
